package com.ugoodtech.mdcc.web.service;

/* Copyright (C) Ugoodtech, Inc - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 */

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ugoodtech.mdcc.core.utils.ZxingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.OutputStream;

@Service
@Transactional(readOnly = true)
public class QRService {

    private static final Logger logger = LoggerFactory.getLogger(QRService.class);


    /**
     * 输出二维码
     * @param outputStream
     */
    public void getQrImage(Object object, OutputStream outputStream) {

            ObjectMapper objectMapper = new ObjectMapper();
            String json = null;
            try {
                json = objectMapper.writeValueAsString(object);
                logger.info(json);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
            if (json != null) {
                ZxingHandler.encode(json, 200, 200, outputStream);
            }

    }

    /**
     * 输出Url二维码
     * @param outputStream
     */
    public void getUrlQrImage(String url, OutputStream outputStream) {


            ZxingHandler.encode(url, 200, 200, outputStream);


    }

}
